from typing import List


def memory_sort(memory_list: List[str]) -> List[str]:
    mem_cap = []
    for j in range(len(memory_list)):
        mem_cap.append([j, transformer(memory_list[j])])
    mem_cap.sort(key=lambda x: x[1])

    result = []
    for t in mem_cap:
        result.append(memory_list[t[0]])
    return result


def transformer(memory: str) -> int:
    total = 0
    temp = ""
    for i in range(len(memory)):
        if memory[i] == "M":
            total = total + int(temp)
            temp = ""
        elif memory[i] == "G":
            total = total + int(temp) * 1024
            temp = ""
        elif memory[i] == "T":
            total = total + int(temp) * 1024 * 1024
            temp = ""
        else:
            temp += memory[i]
    return total


if __name__ == '__main__':
    memories = []
    n = int(input().strip())
    for _ in range(n):
        memories.append(input().strip())
    sorted_mem = memory_sort(memories)

    for r in sorted_mem:
        print(r)

"""
3
1G
2G
1024M

5
1T
20M
3G
10G6T
3M12G9M
"""
